package org.bluedream.core.config.shiro.loginOrganization;

import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName LoginOrgManager  登陆组织管理器
 * @Description TODO
 * @Author Administrator
 * @Data 2022/5/20 11:49
 * @Version
 */
@Data
@NoArgsConstructor
public class LoginOrgManager{

    private static final long serialVersionUID = -3434414553744010746L;
    public static final String LOGIN_ORG_MANAGER_KEY = LoginOrgManager.class.getName() + "_LOGIN_ORG_MANAGER_KEY";
    public static final String LOGIN_ORG_SUBJECT_SESSION_ID = LoginOrgManager.class.getName() + "_LOGIN_ORG_SUBJECT_SESSION_ID";

    private static final Map<String , Object> resources = new HashMap<>();

    public Map<String, Object> getResources() {
        return resources;
    }

    public Object getValue(String key){
        return resources != null ? resources.get(key) : null;
    }

    public Object get(String key){
        return getValue(key);
    }

    public void put(String key, Object value){
        if (key == null){
            throw new IllegalArgumentException("key cannot be null");
        }else if (value == null){
            remove(key);
        }else {
            Object obj = get(key);
            if (obj != null){
                remove(key);
            }
            resources.put(key , value);
        }
    }

    public void remove(String key){
        resources.remove(key);
    }

}